<?php

namespace Trawind\Basics\Commands;

use Illuminate\Console\Command;
use Illuminate\Redis\RedisManager;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Redis;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Trawind\Helpers\SystemHelper;

class SystemDownCommand extends Command
{

    const DOWN_KEY = 'system:down';

    /**
     * The console command signature.
     *
     * @var string
     */
    protected $signature = 'system:down {--message= : The message for the maintenance mode}
                                 {--retry=600 : The number of seconds after which the request may be retried}';


    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Put the application into maintenance mode';


    public function handle()
    {
        $message = $this->option('message') ?? '系统正在维护升级，请稍后再试。';
        $retry = $this->option('retry');

        SystemHelper::redis()->setex(self::DOWN_KEY, $retry, $message);

        $this->comment('Application is now in maintenance mode.');
        return 1;
    }

}